/**
 * 会话存储-存   -------------------------------------------------------会话存储------------------------------------
 * @param {*} key 键名
 * @param {*} value 值
 */
const sessionSet = (key: string, value: any): void => {
    sessionStorage.setItem(key, JSON.stringify(value))
}

/**
 * 会话存储-取
 * @param {*} key 键名
 */
const sessionGet = (key: string): any => {
    const _data: any = sessionStorage.getItem(key)
    try {
        return JSON.parse(_data)
    } catch (e) {
        return _data
    }
}

/**
 * 会话存储-删
 * @param {*} key 键名
 */
const sessionDel = (key: string): void => {
    sessionStorage.removeItem(key)
}

/**
 * 会话存储-删处全部
 */
const sessionClear = (): void => {
    sessionStorage.clear()
}

/**
 * 永久存储-存  -------------------------------------------------------永久存储-----------------------------------
 * @param {*} key 键名
 * @param {*} value 值
 */
const localSet = (key: string, value: any): void => {
    localStorage.setItem(key, JSON.stringify(value))
}

/**
 * 永久存储-取
 * @param {*} key 键名
 */
const localGet = (key: string): any => {
    const _data: any = localStorage.getItem(key)
    try {
        return JSON.parse(_data)
    } catch (e) {
        return _data
    }
}

/**
 * 永久存储-删
 * @param {*} key 键名
 */
const localDel = (key: string): void => {
    localStorage.removeItem(key)
}

export { sessionSet, sessionGet, sessionDel, sessionClear, localSet, localGet, localDel }